Fix qfind function, make it more robust