Refactoring out of huge functions.php