add '!' to $index < count($functions)