Fixed setname() loop. renamed variables for clarity.