Start to refactor into smaller functions.