added encode functions