Fixing variable not defined properly