Improved estimation of local maxima

Split out function to determine local maxima for testing purposes.
Fixed bug in estimating local maxima, where distributions with more
than one maxima, but without maxima nearby each other, would give an
error.
started adding unit tests