made some code clean up and documentation