Added checks for overflow.