Initial refactoring, next comes klass library integration.