add caching to stop memory leak