added some caching code; need to finish it