phase 3 after adding close function