Extract a bit of duplicated code