Added Comments

Added code comments, fixed typos, re-ordered code.