changed nested if to switch