Cleaup up of synchronization code. Now uses the invoke() function instead of looping