wrap commands in try block
chdir to enable deletion of temp dir, tidy up