I removed most of the comments and added a couple of assertions.