moved check to query
get rid of duplicated code