Refactors main application