Refactored internal_functions.