Fixes #14 Close channel if exception occurs

Close the channel when exceptions occur.