added integer overflow check