refactoring almost completed