Corrected some typos.
Changed the error messages.
Refactoring a little bit more.