Fixed a number of typos and removed some redundant code