changed to using coroutines to fix variables issues