better error handling, including the --leave option