It is very difficult for us to "reverse engineer" someone elses code, take a wild guess what it is supposed to do, then come up with a better solution.
I would recommend that you spend a few paragraphs outlining what the program requirements are. The entire program outline could be flawed and it is better to start from scratch.
(E.g.: Where does the data come from? What should happen to it? What should the user see? What can the operator do with it (real-time interaction, post processing, computations, data reduction, pass/fail, saving, printing, changing display modes, etc).