Fixes retry. Fixes exception handling. Adds unit tests.