code cleanup and documentation added