Minor bugfixes and cleanups