code cleanup and added base for sync