fixed scaling function and other stuff