fixed some bugs in the scale algorithm