Refactor solver