Refactor, better use of channels. Only main() writes to stdout now.