Added the clean up code. Understood the ticket_head and ticket_tail better and how we can use it to schedule the waits.