Aim as a non-blocking server and some fixes related to memory leaks