fixed some bugs with the remainder