added caching, seems to fix #7