Added wait statements everywhere