revised some code and added documentation