Clean up the channel when exiting && refactor a bit