Move communication stuff out of main

Split tasks into separate methods and run each one of them in a separate
goroutine.