Don't you end up with one too many samples here? Doesn't r count as a sample?