Cleaned up waiting code