added documentation and fixed bug