Script refactored for manual extraction