Moved Query functionality to model