Did some refactoring and added actual matching