maintain(*): added wait time flag support, tidy up code