Refactored solver