Adding corrected scaling code