consolidate duplicated code