Improved dimming algorithm
