added closing functionality