added memoization for astart