Existing D6 code was partially wrong already. Tried to limit the fixes to new code as much as possible.