wrote FindModeAtThreshold function, untested