Some cleanups and fix wait time calculation