massive refactoring. Uncompleted