refactored js scripts