cleaned up sync code