added documentation and bug fixes