refactoring ImageQuery to make it more testable, add docs