optimize Unary Encoder