Adding proper closing of channels