Refactor a bit
Fix bug in dashboard