Added more comments to the code + minor clean-ups.