Regarding setting $IFS:
for arg in $@; do
A better way to do it is to quote it:
for arg in "$@"; do
because then you can capture newlines and tabs. Bash will automatically convert it to separate parameters, even though there is only one quoted variable.