Ryan Hughes has outlined a useful method of organizing a Grasshopper script.
Instead of posting a Grasshopper script to explain your project, try Ryan Hughes’ method.
He suggests keeping your code readable, modular, reusable and clean.
First image: Example of a Grasshopper stylesheet.
Second image: Updated screenshot for the def with the attribution to Geometria Finland and Toni Österlund for the main components of the original definition.