refactoring. not finished code