Added some comments to the code w/minor improvements