Refactor data management scripts