Changed to more functional style.