Refactorings and query optimizations against database.