refactored code, works with multi-query