Code refactoring for internal functions