Bug fix: app crashes when the device is connected to or diconnected from power source