(doc) added documentation and cleaned up code