almost done with refactoring