Fixed a few errors in misspelled variable names and tidied up some more code.