Switch to using OOP instead of globals
Some more improvements; Soon comes testing