tentatively working memory-efficient version