Use set -e and trap for proper cleanup