Refactoring to simplify functions.