Runs out of memory when subterms are extended