variable "r" is no longer global.

just noticed that the variable "r" was global, simply added a var.