core.php: Improve core replacing routine