Refactor so things can be cached better.