code cleanup and some comments