Fix bug when closing UI