refactoring: remove duplicate logics
refactoring: take the ns from another function