Separate channel close implementation to function.