Correct misspelled variables, added function