Refactored main test setup code