move memory stuff to own utility