added documentation and comments to some functions