Improved retry loop code
Use sprintf instead of concating strings