Refactaring string matcher