fixed bug in scale function