cleaned up some code, added some comments