Semi-final version. All output conforms to specification.