Added ability to pass query objects into query function