Preliminary refactoring before introducing scopes
Added scoped variables and the main solve loop