Changed to switch structure and enhanced for loop