Added if query != None check