Various small fixes

I am going through source and try to understand it, fixing small stuff on the way.