Cleaned up code and restructured send/receive functions