Fixed: SQL syntax and time calculation bugs -- related to sync