Functions refactored