Refactor database