replaced if / else with a match