Bug fix in contingency function

Fixed segfault due to improper typing (using a possibly negative 'bin' index).