Misc improvements and bug fixes