Completed database refactor