Refactored the scripts