flow: split case statement handling into its own function