Change threshold to use types

Refactor the threshold code and change to a type based api. Added a bit of documentation to readme.