Fixed variables and redundant code, also made variables private and classes/methods local where needed