first part of big refactoring