optimized stage scaling code