Add wait handling code