Refactored code to support primary principal.
Fixed issue with merge conflicts