Various bugfixes/enhancements