Moved try block inside for-loop for better fault tolerance.