added close(), disconnect handlers, and fixed a few bugs