some cleanup and added some comments