Extract function
Clean up test script