Refactor the caching stuff out.