added documentation and some fixes