refactoring del javascript