fixing issue with misuse of $name variable