add tostring
clean up scope, and some logging, bug fixes