implemented #1 and slightly improved exception handling