Refactored diagram parser