Fix the overflow problem in a smarter way