Comments added, code cleanup and improved