bugfix in memoisation code