Added extra memory switch and function, made them more finegrained