Add max_sleep_sec option and improve sleep time calculation generally