Added documentation comments and tweaked code.