Remove undefined behaviour in selective implementation