fixed memory leaks on the server side. Changed entity to use a struct for encode/decode.