Improved overall robustness of the script.