Refactored solver code.