Tweaked callbacks to prevent race condition (https://github.com/libevent/libevent/issues/104)
Tweaked callbacks to prevent race condition (https://github.com/libevent/libevent/issues/104)