Misc improvements and bugfixes.