closing modal not called correctly