Misc bugfixes