Misc improvements and bugfixes