code clean up, added documentation