- refactoring to make the logic flow more clearer