consolidate duplicated code

... and make sure all occurrences are using the updated version