For #1987: remove code duplication