add global exception handler and some bug fix