Various and sundry bugfixing