Refactoring code in dashboard