Working solver
Refactored the solver and added tests for it