partial implementation of finding peak