litte bugfixes

Hi,

can someone please review this fixes.
I've added comments to the commits to explain them.

thanks
Dirk