Tweaks to scaling code