fixed matcher bug, some refactoring