fixed bugs in range scaling