changed equlity condition to allow for a total difference of B