added encoding functionality