added mh query, refactored query code