Added retry limits and custom permanent error codes