Move logic into case statement to avoid repitition