threshold function fix
Pairwise interface plus various bugfixes.