Refactoring queries (#4)