Refactoring of database queries.