fixed and improved material caching