moved db code to the db files