refactor with switch