Fixed undefined varible errors