Refactor into smaller functions.