Refactored function apply_profile()
Improved documentation