Can you explain how the listen_for_messages() function works?