added set -e and did some cleanup