Fix typos and errors.

Couldn't test this code during the writing so I made some mistakes.