Fix typos.
Clean up code and fix error construction.