Complicated bugfixes