adding memory code