Added memory code from other project