Refactor the app code