Update prepare.sh

make it more robust