variable "n" is needed before it was actually created. bug fixed.