Refactored app.php and delegated work to classes