merged #323 and refactored exception handler

close #323