updated findmatch in order to fix infite loop, added proper output