Use match-case construction to simplify code