re implemented and corrected count logic in mquery