factor out test code