Refactored some portions into an object

WARNING: Class is still untested, continue with procedural until stable.