Fix output overflow/wrapping