cleanup and bugfixes: closing #46, #44