Further fixes and workarounds.
Almost complete version.