Refactoring and renaming internal functions