Smart encoding implementation.