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

Yes I got the point. I will change and send you a pull request if you want.