Move retry to its own func, protect ok with a mutex (draft)