Refactored functions.php