Cleanup. Removed unused code and comments. Moved memoisation to seperate file