Fixed huge bug with query