Pattern match: assorted cleanup and documentation