sync
lots of refactoring