hotfixes (porting errors?)

Please DO NOT just merge this PR. I think this stuff has to be reviewed.
I stumbled upon some errors, which look to me like porting errors or similar, but I don't know it 100%.

I'll add comments to the code lines...

Please close this PR if you address the issues otherwise.