Updated to include GS orthogonalization, use of minimization for 1D solve,
better error handling.