Sanity checking, more comments and documentation.