Discovered that python was a much better language for the task and rewrote the program.