Lots of typos fixed, undefined variables, unused code
oops, typo