Cleaning up with some pattern matching