Bugfix and a couple other minor enhancements to retry logic