how do the heart and the lungs work together