initial refactoring of solver