Finally fixed power failure function.