a few small changes to fix compiler warnings

These also may potentially fix undefined behavior.