Hoist some duplicated code out into a let