0.6.5 fixes

I can't really say I understand much of what is happening here, so please take this with a grain of salt.
But at least it works for me in 0.6.5 now. Maybe it can be used as a base for further investigation.