add logging, and misc small bug fixes
misc commenting, docstringing and bugfixing