Changed to support weighted and directed networks