refactored the receive functions a bit