clean up of code and added comments