refactored the scripts