Used memoization to shave about half an hour off mathcalG runtime