refactor db sync