Fixed undefined variable errors