Better thresholding

__Not ready for merge.__

Continuation of PR #35.