refactor database methods