Some clean-up of memory routines (+ some regression fixes).