Use pattern matching to remove intermediate variable