Great idea, this logic is duplicated in a few places.