fixes, added documentation, refactoring