Added comments and simple rewrite of the code.