Finished all functions needed for encode, will debug against python debug