MISC: refactor to remove code duplication