reimplement glr algorithm