merge smichr's changes as-is
Inline _omatch() code + some simplifications