refactor database and models into files