trying to save memory in D2 calculation