Refactoring, plus fixes for deprecated functionality to be still working