First Complete Refactor

Complete Refactoring to eliminate most compiler warnings. Has broken
gex file reading and several bugs introduced.