Add caching and clean up code.