How to avoid code duplication in a function?

scswift:
I'm basically trying to keep the code that drives everything behind the scenes, and everything protonpack() does, completely separate from eachother.

And it seems like sticking it in a namespace or class might be the best solution, although I am not sure if the IDE will allow me to put that code in a tab by itself rather than sticking it in my main program where I don't want it.

When defining a new class, typically you split it into a declaration, which goes in a .h file in one tab, and its member definitions, which go in a .cpp file in another tab. Then you #include the .h file in your main sketch.