Separated problem logic to a new class. Other changes