refactor database process