fixing poor use of $name variable