some refactoring and building out the database interface