extracted duplicated code