updated communities function to create and pull from the database