(#22250) refactor previous and add spec tests