Fix possible double close