refactoring using patterns from http://blog.golang.org/advanced-go-concurrency-patterns