refactor database script