added waitTime func and better handling when the switch loops