Created separate method for query constction.