Refactor index.php and function.core