Fixed errors regarding the loop in searching methods
Fixed loop issues in searchAndWrite method