refactoring. Partially not working