added documentation and some cleanup