Make shell code more robust