Refactor logic into external scripts.