Got rid of deep if/else nesting inside libs/Application.php