Implemented maximum linesearch iterations.

Previously, if the linesearch optimization never returned true, the linesearch would continue forever, even
when no progress could be made. This adds a high-level check to make sure this condition throws an error.
100 iterations should be enough for any linesearch.