Final commit. Updated README. Added comments. Confirmed that my implementation indeed does have the correct behavior.