fixed #35 #44 addressed #45, major refactorings, added documentation and tests