improved function to split into cases