more cleanup and deal with exceptions