integrated codes and refactored functions.php