Fixed undefined behaviour.