Fixed some memory stuff in mem_tests branch