improved exception handling, improved tests