modified for libevent