improved the retry

increase of number of tries
proper exit on fail