refactor use of a single-use callback

setting the flag before invoking is important in case onExit yields!
Use close event instead of exit

See https://github.com/meteor/meteor/commit/957729c8cefced

Also delete unused var and remove more listeners before kill