Finish pattern matching and tidy up.