cleanup and added some comments