Improved search algorthim