Fixed minor bugs. Added comments to the code.