Communities detection algorithm: clean and working