add check for encoding length