polished up some code and comments