fixed pretty terrible memory leak when running in synchronous mode