Improved the script and added some explanations