added edge checks to extractPeaks() so that edge indeces are taken into account (bunch of nested ifs, unfortunately)