remove code duplication using a defined type