Split out memory and callbacks logic