Reducing the timeout for closing the channel and cleaning up some code