refactoring code to new DB