moved memory creation into its own function (useful for rebasing, for example)