Fixed issue in community cost function