Miscellaneous bugfixes