Reimplemented tas_lgagst

This may still fail in some extremely rare cases.