refactoring alsmost completed