cleaned up encoder