Factor out more duplicate logic