Changed OR to prefer exact matches, and fixed various use-after-move bugs.