rewrite large chunks to use caching instead of unnecessary graph traversal