Loop até {connections} em vez de {pipe_count/2}; dá pau se {connections} for maior.