Refactored linesearch algorithms to be much simpler