migrated some functions in custom.php