fixed some bugs with regard to the remainder calculation.