improved exception handling, more tests