1) Change shell from /bin/sh to /bin/bash
2) More flexible udploop.sh