Handles incoming messages