refactored queries into models