code clean up, added comments