Refactoring code, simplifying the js on the dashboard page