add a unit test and fix sync function