writing encoding functions