Extracting logic into methods; converting to switch() block.