added exception and hits check in search function