Refactor into functions.