generalize reset database script
fix error handler