Fix memory leak, refactor to close all channels in caller, do input validation up front