Refactor analyze scripts