cleaned up some code, added documentation