moves memory to own module, factors out common stuff
Co-authored-by: Tim Asp <707699+timothyasp@users.noreply.github.com>