Fixed bugs in scaling