Structure of Message-Passing Programs