refactored dashboard and widget JS code