Clean up logging and debugging code
Initial retain support
Added retain flag support, implemented socket close handler for deallocating resources.
Stability tests executed