* Adding a close method for graceful shutdown

@ronkorving could you have a quick look? I will test it further with some of our tools in the next few hours.
You're not returning early in this block, so you're still setting _onClose a few lines later.