renamed variable $name to $index