Tighten up some logic and add comments for issue #3.