Move memoisation into its own file.