Removing code duplication from Caleadapter.c (#606)