Added memory routines and self_test