clean up function defs
add encoding test