close() should be done in a finally block