add wait for reply in function