More bugfixes I didn't check for actual workingness.