Fixed memorization bugs