Some cleanups and fix pattern matching

Should fix http://bugs.openmw.org/issues/527