Abstracted out query logic from app logic, since I'm going to have to start doing things with the result next