Minor refactoring. Fixed profile saving.