refactoring of LS solver