fix severe performance bug of not memoizing from general algorithm