improved exception handling, minor code adjustments