Fix variable checking logic