Improved send/receive and restructured some func