debugged loop; added reverse and buffer scan