Warning fixes

I didn't add casts in not obvious cases, there there should be no regressions.