Improves the entire code making better use of Bash script