fix threshold underflow possibility