simplify and extend sync-db, and fix linreg ranges