use close rather than end to catch failures