An algorithm for detecting overlapping and multilayer communities in complex networks