Use waitFor instead of sleeping.