finished encode, needs testing