Implement timeForBackgroundSync(), fixed some synchronization bugs on sync thread, cleaned up a bunch of dead code from old sync service