Fix variable scope passing