Fix bug in mem3, passes all tests