refactored the receive method