refactoring queries and this and that