Permanent failure could sometimes be temporary failure
Tidy up and add comments