Added close and end handlers