Added lots of comments on functions to explain what they do.
Also fixed an issue where the object scope attributes query string
was wrong and always tried to compare against the account URI instead
of the domain specific URI.