Modify to stop fun of the application and refactor