Widget JS refactoring