Handle power management events.
Minor refactoring.