source code cleanup, add libevent event loop