closes #1 and slightly improved exception handling