Add comments.
Fix wrong variable names, and remove unnecessary line. bugid:112416
Use default theme if "themeId" parameter is not set. bugid:112416
Fix wrong permission check of sitepath fields. bugid:112416