Working version with refactored query methods