Clear up warnings and undefined behaviour.