Minor code fixes, fixed typos, added comments