move retries counter decrease to the end of if block
document the hooks