Fixed some bugs and edge cases.
Added some notes.