Fixed typos, added missing comments and checks for null