moved check to query