Refactored main.php