moved close(done) in the proper location