if you're curious about the state of the art for this kind of thing, it might be worth reading a primer or two on modern data compression techniques and how they work. You might find out how some of what you're trying to do here can be done, but more elegantly and efficiently, and *why* it works better
The messiah!!!