add 'on.exit' to safely exit if something fails