Fix memoization of X_ids and reverse_X_ids.