fixes some exception handling bug