added overflow check