fixed to work with directed graphs