polishing auto-scaling code