Start refactoring database code