Misc bugfixes, improvements, testing, etc