Close function correctly.