Added comments to document some codes