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

Yes please. I will not be able to merge w/o a pull request.