Code refactoring and cleanup of the `diagrams` tool