Added exit on error (set -e)
fixed missing ] error