clean up and refactoring around sync writes