Abstracted php scripts to functions.php