moving functions from cleanup.php to the core module