fixed overflow logic