threshold function

implements #6