Starting refactoring. Work in progress