Clean up and improve caching