factor out testing code