restructure exception handling