Added safety precaution against integer overflow