Fix potential crash on close