improved screen scaling code