The 면서 refers to the part that is coming before. The part after 면서 is the main sentence. The MAIN action happens WHILE the action in the first part (before -면서) of the sentence happens.
Many grammar patterns follow that logic in Korean.
-니까 (BECAUSE OF what happens in the clause before 니까)
-면 (IF the thing before 면 happens)