Added code to handle empty query.