Cleaned the source code

Fixed some typos and added some more remarks and comments.