Added check for is valid query