Steal algorithm end check from Laspack