Reorganize test code