Remove unused varaibles and fix error checking in cuda_sync().