General refactoring on Diagram implementation