refactor for message receiving