upgraded algorithm for searching