Refactoring of diagram module.