fixed first function and glr algorithm