adds improved exception handling