fix array index issues in functions.php