fixing memory leak by better aligning with the AnyEvent paradigm