client script refactored