finally fixed refactoring