Adjustments to MBriskar's PR to reduce memory consumption