finds local extrema and endpoints, labels with markers
refactor