Change guards to pattern matching