Refactor into a more functional style.