Cleanup, add doc, make test more tolerant to timing issues