Tweaked scaling code