Added caching and updated for upstream compatibility.