did some cleanup and added some comments