Refactor to utils/db, WIP