add code to check memory