refactoring not entirly working