Fix a bug in waiting time calculation