refactor database