bugfix and some small cleanups