Complete re-write from procedural to object oriented. Needs additional testing.