Added graphs; some refactoring