refactoring almost done