Refactor for a more functional style.