Some tidying up of the S3 code.