added logic and started matching loop