Code cleaning and support for on/off events.