tweaked to not block the event loop