Refactor communities.js