Improved documentation
Added quite a few comments to the code.