Turned some functions into lambda functions to save space and make it easier to use and changed more varibles to type var along with cosmetic changes