refactoring some profile loading code