some code cleanup
added some comments