added caching and fixed layering issues