renamed the function and did refactoring