Fix encode method