New approach to community detection in networks