Consolidating code, and making more object oriented