refactored into one function
refactor