Improved code on searching data