finished database refactoring