Minor bugfixes and cleanup