Cleaned up some comments and simplified some of the code, done as part of code review, see #1.