Implemented proper waiting in client