Clean up test script
Fix optimization function