Move encode/decode functions to utils and remove extraneous stuff?