Minor bugfixes and small cleanups