more flexible bug fix for overflow