Modified code to support power up/down events