Fixed undefined variables and other stuff.