Added code to shutdown device if the device is already in booted state while erasing content and settings

You don't need this. You can erase the contents after the simulator state has been changed from "Booted" to "Shutdown"