more code cleaning and documentation

code cleanup and documentation of some functions