some cleanup, updated and added some comments