finished implementing encoding