Fixed receive segmentation fault because of multiple messages from daemon at once

Additional added some asserts and fixed memory leaks