Added close handler, updated comments