Removed all $(...) with sudo to avoid subshell requiring password entry again.  Created RET_VAL variable to handle return values instead