cleanups and a few small bugfixes