refactoring + adding weighted directed graph