merge both switch statements to optimize