Overhaul of Bash script