improved exception handling