refactoring, DRY up query methods

Try 2 - see if code climate hooks works + some refactoring