added documentation and code clean up