small code cleanup and added some comments