Added some more comments to make the algorithms a bit more clearer