refactored one function