code cleanup
Added dimming support