added more documentation and some cleanups