encoder code cleanup