Added parameter for controlling sleep time.