Moved on_close commit handler to its own function.