Added "waitForKS" function