corrected overflow detection to make it functional