Bug fix in the wait time, slight refactor of logic