One more thing - have you considered extracting unrelated source code into separate files ?
You can use source util.sh command to import functions from other files, this way you can have main file clean and just validating input and calling other functions.