refactored widget code for html safe js