Cleaned up code, started actually freeing malloced memory, serialize message