fixing obviously wrong func calls and types

The patch fixes compile warnings and other potential troubles.
I don't have a test that demonstrates the 'other' troubles, but the patch is quite straighforward, I think.