script refactored