Refactored solver a little bit.