Fixed receive segmentation fault because of multiple messages from daemon at once and fixed some memory leaks.