Refactor into nicer class structure.