Using case instead of if and added tests