reorganize, add debug flag for error handler