fix #210 and some small cleanups