Added check for query set to None