Moved variable set inside check