i don't like this loop and wait here. there must be a better solution.