Fix exception handling and remove debug output