fix for fix #39 and some cleanups