add support for multiple channels, refactor