working LS solver. Slow and not DRY