Another small improvement for this example is to skip the CDF if "a" is positve, because in that case "p" is greater than 0.5.