Added Scaling code adapted from Jeff