set -u and fixes