Drag the threshold code back in

Pulling master to active