how does the heart  function as a pump